package com.dzzw.Servlet.DepartmentServlet;

import com.dzzw.Dao.DepartmentDao;
import com.dzzw.Model.Department;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/View/DepartmentAddServlet")
public class DepartmentAddServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String department_name = request.getParameter("department_name");
        Department department = new Department(department_name);
        DepartmentDao departmentDao = new DepartmentDao();
        departmentDao.DepartmentAdd(department);
        System.out.println("部门信息添加成功！");
        response.sendRedirect("/View/SelectAllDepartment.jsp");
    }
}
